package org.example.stream.demo;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class FlatMapMain {
    public static void main(String[] args) {
        List<List<String>> nestedList = Arrays.asList(
                Arrays.asList("apple", "banana"),
                Arrays.asList("orange", "grape", "kiwi"),
                Collections.emptyList(),
                Arrays.asList("mango")
        );

        List<String> rs1 = nestedList.stream().filter(l -> !l.isEmpty()).flatMap(Collection::stream).collect(Collectors.toList());
        System.out.println(rs1);
    }
}
